package cn.xzchain.concurrency.singleton;

import cn.xzchain.concurrency.annoations.NotRecommend;
import cn.xzchain.concurrency.annoations.ThreadSafe;

/**
 * @author lihang
 * @date 2018/5/7.
 * @description 懒汉模式使用synchronized修饰变成线程安全的,性能开销大
 */
@ThreadSafe
@NotRecommend
public class Singleton3 {

    private Singleton3(){
    }

    private static Singleton3 instance = null;


    /**静态工厂模式*/
    public static synchronized Singleton3 getInstance(){
        if (instance == null){
            instance = new Singleton3();
        }
        return instance;
    }
}
